package test.studyjdk.list;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CurrentChange {
    public static void main(String[] args) {
        CollectionThread collectionThread = new CollectionThread();
        CollectionThread1 collectionThread1 = new CollectionThread1();
        for (int i = 0; i < 10; i++) {
            new Thread(collectionThread1).start();
        }
    }
}


class CollectionThread implements Runnable{

    private static List<String> list = new ArrayList<>();

    static {
        list.add("aa");
        list.add("bb");
        list.add("cc");
        list.add("dd");
    }

    @Override
    public void run() {
        for (String s : list) {
            System.out.println(s);
            list.add("fafaf");
        }
    }
}

class CollectionThread1 implements Runnable{

    private static List<String> list = new CopyOnWriteArrayList<>();

    static {
        list.add("aa");
        list.add("bb");
        list.add("cc");
        list.add("dd");
    }

    @Override
    public void run() {
        for (String s : list) {
            System.out.println(s);
            list.add("fafaf");
        }
    }
}
